package org.sjm.samples.dao;

import java.util.List;

import org.sjm.samples.model.ExamTest;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class ExamTestDAOImpl extends BaseHibernateDAO<ExamTest> implements IExamTestDAO {

	@Override
	public List<ExamTest> FindAllExamTests() {
		return this.find("FROM ExamTest");
	}

	@Override
	public ExamTest getExamTestById(Integer id) {
		return this.get(id);
	}

	@Override
	public Integer createExamTest(ExamTest examTest) throws Exception {
		this.save(examTest);
		return examTest.getId();
	}

	@Override
	public Integer editExamTest(ExamTest examTest) throws Exception {
		this.update(examTest);
		return 1;
	}

	@Override
	public Integer deleteExamTest(Integer id) throws Exception {
		ExamTest exsitsExamTest = this.get(id);
		if(exsitsExamTest != null){
			this.delete(exsitsExamTest);
		}
		return 1;
	}
	
	@Override
	public List<Integer> getTestIdByType(Integer subId, Integer testTypeId) {
		return null;
	}

	@Override
	public List<ExamTest> getTestListByIds(List<Integer> ids) {
		return null;
	}

	@Override
	public List<ExamTest> getTestListBySubAndTestType(Integer subId, Integer testTypeId) {
		return null;
	}

	@Override
	public List<ExamTest> getTestListByIdList(List<Integer> randomTestList) {
		return null;
	}

	@Override
	public List<ExamTest> getExamTestsBySubId(Integer subId) {
		return this.queryForList("FROM ExamTest AS et WHERE et.subId=? ", new Object[]{subId});
	}

	@Override
	public void deleteExamTestBySubId(Integer subId) {
		List<ExamTest> examTestList = getExamTestsBySubId(subId);
		if(examTestList != null){
			this.deleteAll(examTestList);
		}
	}
	
	
	/*
	@Autowired
	private SessionFactory sessionFactory;
	
	public Session getSession(){
		return this.sessionFactory.getCurrentSession();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ExamTest> findAllExamTests() {
		Session session = getSession();
		String hql = "FROM ExamTest";
		List<ExamTest> examTestList = session.createQuery(hql).list();
		return examTestList;

	}
	
	@Override
	public ExamTest getExamTestById(Integer id){
		Session session = getSession();
		return (ExamTest) session.get(ExamTest.class, id);
	}
	
	@Override
	public void editExamTest(ExamTest examTest){
		Session session = getSession();
		session.update(examTest);
	}
	
	@Override
	public void createExamTest(ExamTest examTest){
		Session session = getSession();
		session.save(examTest);
	}
	
	@Override
	public void deleteExamTest(Integer id){
		Session session = getSession();
		ExamTest examTest = getExamTestById(id);
		if(examTest != null){
			session.delete(examTest);
		}
	}

	*/
}
